home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / errplot.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  119 lines

  1. ; $Id: errplot.pro,v 1.5 1997/03/27 23:39:49 kirk Exp $
  2. ;
  3. ; Copyright (c) 1983-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. Pro Errplot, X, Low, High, Width = width
  8. ;+
  9. ; NAME:
  10. ;    ERRPLOT
  11. ;
  12. ; PURPOSE:
  13. ;    Plot error bars over a previously drawn plot.
  14. ;
  15. ; CATEGORY:
  16. ;    J6 - plotting, graphics, one dimensional.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    ERRPLOT, Low, High    ;X axis = point number.
  20. ;
  21. ;    ERRPLOT, X, Low, High    ;To explicitly specify abscissae.
  22. ;
  23. ; INPUTS:
  24. ;    Low:    A vector of lower estimates, equal to data - error.
  25. ;    High:    A vector of upper estimates, equal to data + error.
  26. ;
  27. ; OPTIONAL INPUT PARAMETERS:
  28. ;    X:    A vector containing the abscissae.
  29. ;
  30. ; KEYWORD Parameters:
  31. ;    WIDTH:    The width of the error bars.  The default is 1% of plot width.
  32. ;
  33. ; OUTPUTS:
  34. ;    None.
  35. ;
  36. ; COMMON BLOCKS:
  37. ;    None.
  38. ;
  39. ; SIDE EFFECTS:
  40. ;    An overplot is produced.
  41. ;
  42. ; RESTRICTIONS:
  43. ;    Logarithmic restriction removed.
  44. ;
  45. ; PROCEDURE:
  46. ;    Error bars are drawn for each element.
  47. ;
  48. ; EXAMPLES:
  49. ;    To plot symmetrical error bars where Y = data values and 
  50. ;    ERR = symmetrical error estimates, enter:
  51. ;
  52. ;        PLOT, Y            ;Plot data
  53. ;        ERRPLOT, Y-ERR, Y+ERR    ;Overplot error bars.
  54. ;
  55. ;    If error estimates are non-symetrical, enter:
  56. ;
  57. ;        PLOT,Y
  58. ;        ERRPLOT, Upper, Lower    ;Where Upper & Lower are bounds.
  59. ;
  60. ;    To plot versus a vector of abscissae:
  61. ;
  62. ;        PLOT, X, Y          ;Plot data (X versus Y).
  63. ;        ERRPLOT, X, Y-ERR, Y+ERR  ;Overplot error estimates.
  64. ;
  65. ; MODIFICATION HISTORY:
  66. ;    DMS, RSI, June, 1983.
  67. ;
  68. ;    Joe Zawodney, LASP, Univ of Colo., March, 1986. Removed logarithmic
  69. ;    restriction.
  70. ;
  71. ;    DMS, March, 1989.  Modified for Unix IDL.
  72. ;       KDB, March, 1997.  Modified to used !p.noclip
  73. ;-
  74.     on_error,2                      ;Return to caller if an error occurs
  75.     if n_params(0) eq 3 then begin    ;X specified?
  76.         up = high
  77.         down = low
  78.         xx = x
  79.        endif else begin    ;Only 2 params
  80.         up = x
  81.         down = low
  82.         xx=findgen(n_elements(up)) ;make our own x
  83.        endelse
  84.  
  85.     if n_elements(width) eq 0 then width = .01 ;Default width
  86. ;
  87.     n = n_elements(up) < n_elements(down) < n_elements(xx) ;# of pnts
  88.     xxmin = min(!x.crange)    ;X range
  89.     xxmax = max(!x.crange)
  90.     yymax = max(!y.crange)  ;Y range
  91.     yymin = min(!y.crange)
  92.  
  93.     if !x.type eq 0 then begin    ;Test for x linear
  94.         ;Linear in x
  95.         wid =  (xxmax - xxmin) * (width/2.) ;bars = .01 of plot wide.
  96.         endif else begin        ;Logarithmic X
  97.         xxmax = 10.^xxmax
  98.         xxmin = 10.^xxmin
  99.         wid  = (xxmax/xxmin)* (width/10.)  ;bars = .01 of plot wide
  100.         endelse
  101. print,!x.type, wid
  102. ;
  103.     for i=0,n-1 do begin    ;do each point.
  104.         xxx = xx[i]    ;x value
  105.         if (xxx ge xxmin) and (xxx le xxmax) then begin
  106.           if !x.type eq 0 then begin
  107.             x0 = xxx-wid & x1 = xxx+wid
  108.           endif else begin
  109.             x0 = xxx * (1.0-wid) & x1 = xxx*(1.0+wid)
  110.           endelse
  111.           plots,[x0,x1,xxx,xxx,x0,x1],$
  112.               [down[i],down[i],down[i],up[i],up[i],up[i]], $
  113.               noclip=!p.noclip
  114.         endif
  115.         endfor
  116.     return
  117. end
  118.  
  119.